package controlers;

import java.util.HashMap;
import java.util.Map;

import models.Banda;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class BandControler extends ActionSupport 
{
	private String nome, integrantes, history;
	@SuppressWarnings("unchecked")
	@Override
	public String execute()
	{
		Map<String,Banda> Bandas = (Map<String,Banda>)ActionContext.getContext().getApplication().get("Bandas");
		if(Bandas == null) 
		{
			Bandas = new HashMap<String,Banda>();
			ActionContext.getContext().getApplication().put("Bandas", Bandas);
		}
		if(!Bandas.containsKey(nome))
		{
			Banda newBand = new Banda(nome, integrantes.split(";"));
			newBand.setHistoria(history);
			Bandas.put(nome, newBand);
			return "sucess";
		}
		return "fail";
	}
	public String getNome() {
		return nome;
	}
	public void setNome(String nome) {
		this.nome = nome;
	}
	public String getIntegrantes() {
		return integrantes;
	}
	public void setIntegrantes(String integrantes) {
		this.integrantes = integrantes;
	}
	public String getHistory() {
		return history;
	}
	public void setHistory(String history) {
		this.history = history;
	}
}
